Skip to content

Add utilities for management of downloadable assets#386

Merged
ebrahimebrahim merged 8 commits into
mainfrom
377-support-local-versions-of-the-resources-that-are-downloaded
Oct 9, 2025
Merged

Add utilities for management of downloadable assets#386
ebrahimebrahim merged 8 commits into
mainfrom
377-support-local-versions-of-the-resources-that-are-downloaded

Conversation

@ebrahimebrahim
Copy link
Copy Markdown
Collaborator

@ebrahimebrahim ebrahimebrahim commented Sep 19, 2025

Closes #377.

This adds some downloadable-asset-management utilities to a new module openlifu.util.assets, exposing ways to install assets from local files rather than via internet. Below is an overview of how to use these utilities.


One can now call run_reconstruction with download_masking_model set to False. This will skip the download of the MODNet weights, instead requiring the user to somehow ensure the model weights are installed. They can be installed from file using the newly added openlifu.util.assets.install_modnet_from_file.


There is now a way of importing kwave while skipping its automatic download of binaries: kwave = openlifu.util.assets._import_kwave_inertly(). We need to do this in order to get the binary paths from kwave to support offline use, or delayed download after a prompt, etc. The way it's done is not pretty, but even if we upgrade to the latest k-wave as of writing this it should still work. There is a unit test that uses this to make sure we catch any issues while upgrading kwave.


To check if kwave binaries are present, one can now do this:

all(p.exists() for p,_ in get_kwave_paths())

And then if they are not present then one can

download_and_install_kwave_assets()

if there is an internet connection, otherwise use install_kwave_asset_from_file on individual needed files. The names of the needed files are

[p.name for p,_ in get_kwave_paths()]

Full disclosure: Many of the added unit tests were AI generated. They were all vetted by me.

@ebrahimebrahim ebrahimebrahim linked an issue Sep 19, 2025 that may be closed by this pull request
@ebrahimebrahim ebrahimebrahim changed the title 377 support local versions of the resources that are downloaded Add utilities for management of downloadable assets Sep 19, 2025
@ebrahimebrahim ebrahimebrahim force-pushed the 377-support-local-versions-of-the-resources-that-are-downloaded branch from aea41d3 to 4630d14 Compare September 19, 2025 21:50
Copy link
Copy Markdown
Contributor

@sadhana-r sadhana-r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this via OpenwaterHealth/SlicerOpenLIFU#479 and it worked as expected

This is work towards #377 which will add more things that need to use
PathLike
This allows you to now call run_reconstruction with
download_masking_model set to False. This will skip the download of the
MODNet weights, instead requiring the user to somehow ensure the model
weights are installed. They can be installed from file using the newly
added openlifu.util.assets.install_modnet_from_file.
This is a way of importing kwave while skipping its automatic download
of binaries. We need to do this in order to get the binary paths from
kwave to support offline use, or delayed download after a prompt, etc.
It's not pretty, but even if we upgrade to the latest k-wave it should
still work. I will add a unit test that uses this to make sure we catch
any issues while upgrading kwave.
To check if kwave binaries are present, one can now do this:

```
all(p.exists() for p,_ in get_kwave_paths())
```

And then if they are not present then one can

```
download_and_install_kwave_assets()
```

if there is an internet connection, otherwise us
`install_kwave_asset_from_file` on individual needed files.
The names of the needed files are

```
[p.name for p,_ in get_kwave_paths()]
```
This is needed to prevent kwave from getting auto imported just by
importing openlifu. Otherwise we can never jump ahead of kwave's
auto-download of its binaries to offer alternative ways of getting the
binaries within openlifu.
@ebrahimebrahim ebrahimebrahim force-pushed the 377-support-local-versions-of-the-resources-that-are-downloaded branch from 4630d14 to a3c8f57 Compare October 9, 2025 22:25
@ebrahimebrahim ebrahimebrahim enabled auto-merge (rebase) October 9, 2025 22:25
@ebrahimebrahim ebrahimebrahim merged commit d9862a9 into main Oct 9, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support local versions of the resources that are downloaded

2 participants